package manage.actions;

import javax.servlet.http.Cookie;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import manage.commons.Constants;
import manage.commons.annontations.RequiredLogin;
import manage.commons.utils.CookieUtils;

@RequiredLogin
public class LogoutAction extends BaseAction {

	private static final long serialVersionUID = 1454290375051949551L;

	@Override
	@Action(results = { @Result(name = SUCCESS, type = "redirect", location = Constants.LOGIN_PAGE) })
	public String execute() throws Exception {
		request.getSession().invalidate();
		CookieUtils.removeCookie(response, Constants.COOKIE_U);
		CookieUtils.removeCookie(response, Constants.SUPERMANAGER_KEY);
		Cookie c = new Cookie(Constants.COOKIE_U, "");
		c.setPath("/");
		c.setMaxAge(0);
		getResponse().addCookie(c);
		return SUCCESS;
	}

}
